var jdbc = require('../db/jdbc.js');
var Q = require('q');
var Widgets = exports;


/**
 * Get user widgets
 * @param  {String} userId
 * @return {Promise}
 */
Widgets.getWidgets = function(userId) {
    var defer = Q.defer();
    jdbc.query('select * from t_widget A left join t_widget_config B on A.id = B.widgetId where userId =? order by x,y', [userId])
    .then(function(rows){
        defer.resolve(rows);
    }).catch(function(err){
        defer.reject(err);
    });

    return defer.promise;
};